import { ref, watch } from 'vue'
import type { UnionFormConfigType } from '../types/UnionFormConfigType'

export function useConfig() {
    const config = ref<UnionFormConfigType[]>([])

    const setConfig = (newConfig: UnionFormConfigType[]) => {
        config.value = newConfig
    }

    const getConfig = () => {
        return config.value
    }

    const getFieldByProp = (prop: string) => {
        return config.value.find(item => item.prop === prop)
    }

    return {
        config,
        setConfig,
        getConfig,
        getFieldByProp
    }
} 